package com.ibmeeting.modules.security.security;

import com.ibmeeting.utils.enums.LoginTypeEnum;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

public class VerificationCodeAuthenticationToken extends AbstractAuthenticationToken {
    private final Object principal; // 手机号/邮箱
    private  String code;      // 验证码
    private final LoginType loginType; // 枚举PHONE/EMAIL

    public enum LoginType { PHONE, EMAIL }

    // 未认证构造方法
    public VerificationCodeAuthenticationToken(Object principal, String code, LoginType loginType) {
        super(null);
        this.principal = principal;
        this.code = code;
        this.loginType = loginType;
        setAuthenticated(false);
    }

    // 已认证构造方法
    public VerificationCodeAuthenticationToken(Object principal,
                                               Collection<? extends GrantedAuthority> authorities,
                                               LoginType loginType) {
        super(authorities);
        this.principal = principal;
        this.loginType = loginType;
        super.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() { return this.code; }
    @Override
    public Object getPrincipal() { return this.principal; }
}